package com.lovo.csc.controller;


import com.lovo.csc.entity.Ding;
import com.lovo.csc.entity.Purchase;
import com.lovo.csc.service.IDingService;
import com.lovo.csc.service.IFrozenService;
import com.lovo.csc.service.IPurchaseService;
import com.lovo.remoteservice.ICommodityService;
import com.lovo.sscsys.remoteService.IsscsysRemoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/ding")
@Api(tags = "购物结算")
public class DingController {
    @Autowired
    IDingService service;
    @Autowired
    IPurchaseService purchaseService;
    @Autowired
    ICommodityService commodityService;
    @Autowired
    IsscsysRemoteService isscsysRemoteService;
    @Autowired
    IFrozenService frozenService;
    @GetMapping("dong/{name}")
    public boolean dong(@PathVariable("name") String name){
        isscsysRemoteService.updateState(name,"冻结");
        this.Kdong(name);
        return true;
    }
    @GetMapping("Bdong/{name}")
    public boolean Bdong(@PathVariable("name") String name){
        isscsysRemoteService.updateState(name,"正常");
        this.KBdong(name);
        return true;
    }
    @PutMapping("updateFrozenState/{name}/{state}")
    @ApiOperation(value = "修改报价状态")
    public boolean UpdateFrozenState(@PathVariable("name") String name,@PathVariable("state") String state){
        System.out.println(name+" "+state);
        frozenService.updateFrozenState(name,state);
        return true;
    }
    public boolean Kdong(String name){
        commodityService.setFreeze(name,1);
        return true;
    }

    public boolean KBdong(String name){
        commodityService.setFreeze(name,0);
        return true;
    }




    @GetMapping("findDing")
    @ApiOperation(value = "查询订单")
    public List<Ding> findDing(){
        List<Ding> dings=service.list();
        return dings;
    }

    @GetMapping("findPurchase")
    @ApiOperation(value = "查询商品详细信息")
    public List<Purchase> findPurchase(){
        List<Purchase> purchases=purchaseService.list();
        return purchases;
    }

    @GetMapping("findName/{name}")
    public List<Purchase> findName(@PathVariable("name") String name){
       List<Purchase> purchases= purchaseService.findByName(name);
        return purchases;
    }

    @GetMapping("tianding")
    public boolean tianding(Ding ding){
        service.save(ding);
        return true;
    }

    @GetMapping("tianxiang")
    public boolean tianXiang(Purchase purchase){
        purchaseService.save(purchase);
        return true;
    }

}
